package com.wiscom.portal.demo.controller;

import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;

import org.springframework.web.portlet.ModelAndView;
import org.springframework.web.portlet.mvc.AbstractController;
import java.util.*;

import com.wiscom.portal.demo.entity.Jc;
import com.wiscom.portal.demo.service.JcService;

public class JcViewController extends AbstractController{
	
	private JcService jcService;
	
	/**
	 * 处理来自<portlet:renderURL>的请求
	 * 第一次进入该portlet默认执行该方法
	 * author:yyu date:2011-7-19
	 */
	@Override
	protected ModelAndView handleRenderRequestInternal(RenderRequest request, RenderResponse response) throws Exception {
		Map<String,Object> params = new HashMap<String,Object>();
		params.put("query_jcmc", getParameter("query_jcmc",request));
		List<Jc> jcList = jcService.query(params);
		Map<String,Object> model = new HashMap<String,Object>();
		model.put("jcList", jcList); 
		return new ModelAndView("jc/jcView","model",model);
	}
	
	/**
	 * 处理来自<portlet:actionURL>的请求
	 * author:yyu date:2011-7-19
	 */
	@Override
	protected void handleActionRequestInternal(ActionRequest request, ActionResponse response) throws Exception {
		super.handleActionRequestInternal(request, response);
	}

	public void setJcService(JcService jcService) {
		this.jcService = jcService;
	}

	
	/** 从页面获得参数值,并将返回至前台页面
	 *  author:yyu date:2011-7-19
	 */
	private String getParameter(String param,RenderRequest request){
		String str = request.getParameter(param);
		request.setAttribute(param, str);
		return str;
	}
	
}
